Home:ALL Converter>how to specify "excluded_fields" when using diff_against in simple_history in Django

how to specify "excluded_fields" when using diff_against in simple_history in Django

Ask Time:2021-11-01T20:49:28         Author:Andrew Toole

Json Formatter

I am using diff_against in simple_history in django. See "history diffing" in simple_history docs: https://django-simple-history.readthedocs.io/en/latest/history_diffing.html I have this all working, but it states: "diff_against also accepts 2 arguments excluded_fields and included_fields to either explicitly include or exclude fields from being diffed." I can't figure out how to pass these fields. Here is what I have that is working (without any include or exclude fields):

def historical_changes(qry, id):
    changes = []
    if qry is not None and id:
        last = qry.first()
        for all_changes in range(qry.count()):
            new_record, old_record = last, last.prev_record
            if old_record is not None:
                delta = new_record.diff_against(old_record)
                changes.append(delta)
            last = old_record
    return changes

and I call it in a detail view using:

changes = historical_changes(hpn.history.all(), hpn.pk)

This all works. I then tried to incldue the "exclude_field". These are what I tried, but none worked:

delta = new_record.diff_against(old_record, excluded_fields('geom'))
or
delta = new_record.diff_against(old_record).excluded_fields('geom')
or
delta = new_record.diff_against(old_record.excluded_fields('geom'))

This is likley something quite simple, but I'm not figuring it out. Any help would be great. Thanks.

Author:Andrew Toole,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/69797159/how-to-specify-excluded-fields-when-using-diff-against-in-simple-history-in-dj
yy